/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.hcht.xrlh.zfdxktitle.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.hcht.xrlh.sx.entity.DrSx;
import com.hcht.xrlh.zfdxktitle.dao.DrZfdxkTitleDao;
import com.hcht.xrlh.zfdxktitle.entity.DrZfdxkTitle;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.service.CrudService;
import com.thinkgem.jeesite.common.utils.StringUtils;

/**
 * 执法对象属性设置Service
 * @author lrz
 * @version 2016-12-20
 */
@Service
@Transactional(readOnly = true)
public class DrZfdxkTitleService extends CrudService<DrZfdxkTitleDao, DrZfdxkTitle> {

	@Autowired
	private DrZfdxkTitleDao drZfdxkTitleDao;
	
	public DrZfdxkTitle get(String id) {
		return super.get(id);
	}
	
	public List<DrZfdxkTitle> findList(DrZfdxkTitle drZfdxkTitle) {
		return super.findList(drZfdxkTitle);
	}
	
	public Page<DrZfdxkTitle> findPage(Page<DrZfdxkTitle> page, DrZfdxkTitle drZfdxkTitle) {
		return super.findPage(page, drZfdxkTitle);
	}
	
	@Transactional(readOnly = false)
	public void save(DrZfdxkTitle drZfdxkTitle) {
		super.save(drZfdxkTitle);
	}
	
	@Transactional(readOnly = false)
	public void delete(DrZfdxkTitle drZfdxkTitle) {
		super.delete(drZfdxkTitle);
	}
	
	@Transactional(readOnly = false)
	public void save(DrSx drSx) {
		for (DrZfdxkTitle drZfdxkTitle : drSx.getDrZfdxkTitleList()){
			if (drZfdxkTitle.getId() == null){
				continue;
			}
			if (DrZfdxkTitle.DEL_FLAG_NORMAL.equals(drZfdxkTitle.getDelFlag())){
				if (StringUtils.isBlank(drZfdxkTitle.getId())){
					drZfdxkTitle.setDrSx(drSx);
					drZfdxkTitle.preInsert();
					drZfdxkTitleDao.insert(drZfdxkTitle);
				}else{
					drZfdxkTitle.preUpdate();
					drZfdxkTitleDao.update(drZfdxkTitle);
				}
			}else{
				drZfdxkTitleDao.delete(drZfdxkTitle);
			}
		}
	}
	
	@Transactional(readOnly = false)
	public void deleteBySx(DrZfdxkTitle drZfdxkTitle) {
		drZfdxkTitleDao.deleteBySx(drZfdxkTitle);
	}
}